const app = getApp()
const WXAPI = require("../../../../api/newApi")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, // 是否显示左上角图标   1表示显示    0表示不显示
      title: 'FB收支记录', // 导航栏 中间的标题
      textColor: '#000', // 标题颜色
      bgColor: '#fff', // 导航栏背景颜色
      isloading: false,
      isColor: true,
    },
    list: [],
    navLs:[
      '我的FB','冻结FB'
    ],
    changeIndex:0,
    pageSize: 20,
    pageNum: 1,
    listTotal: 0,
    lodingtype: 1,
    array: ['1月', '2月', '3月', '4月','5月', '6月', '7月', '8月','9月', '10月', '11月', '12月',],
    date:'',
    year:'',
    month:'',
    pickIndex: 0,
    queryType:'1',//查询类型 1 可用fb 2 冻结fb
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var dates = new Date();
    this.data.month = dates.getMonth() + 1; //获取当前月份(0-11,0代表1月)
    this.data.year = dates.getFullYear();
    this.setData({
      month: this.data.month,
      pickIndex: this.data.month - 1
    })
    this.getls()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  bindPickerChange: function(e) {
    this.setData({
      month: parseInt(e.detail.value) + 1
    })
    console.log('picker发送选择改变，携带值为', this.data.month)
    this.getls()
  },
  clickNav(e){
    let index = e.currentTarget.dataset.index
    this.setData({
      changeIndex: index,
      queryType: index + 1
    })
    this.getls()
  },
  getls() { 
    wx.showLoading({
      title: '加载中',
    })
    this.data.date = this.data.year + '-' + this.data.month + '-' + '1'
    var data = {
      pageNum: this.data.pageNum,
      pageSize: this.data.pageSize,
      date: this.data.date,
      queryType: this.data.queryType
    }
    WXAPI.platformFbList(data, (res) => {
      const data = res.result
      if (res.code == 200) {
        // this.data.cardtotal = res.result.total
        if (res.result.total == -1) {
          this.data.listTotal = 0
        } else {
          this.data.listTotal = res.result.total
        }
        this.setData({
          listTotal: this.data.listTotal
        })
        console.log("判断", this.data.pageNum, Math.ceil(this.data.listTotal / this.data.pageSize), this.data.listTotal)
        if (this.data.pageNum >= Math.ceil(this.data.listTotal / this.data.pageSize)) {
          this.setData({
            lodingtype: 1
          })
        } else {
          this.setData({
            lodingtype: 0
          })
        }
        if (this.data.pageNum > 1) {
          this.data.list = this.data.list.concat(res.result.records); //将数据拼接在一起
          this.setData({
            list: this.data.list
          })
        } else {
          this.data.list = res.result.records
          this.setData({
            list: this.data.list
          })
        }
        console.log(this.data.list.length)
        wx.hideLoading({})
      }
    })
  },
    /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("触底了", this.data.pageNum, Math.ceil(this.data.listTotal / this.data.pageSize), this.data.listTotal)
    if (this.data.pageNum >= Math.ceil(this.data.listTotal / this.data.pageSize)) {
      console.log('没有分页')
      this.setData({
        lodingtype: 1
      })
    } else {
      this.setData({
        lodingtype: 0
      })
      this.data.pageNum++; //每触底一次 page + 1;
      this.getls();
    }
  },
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})